package cn.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.idao.IUserDao;
import cn.lei.User;
import cn.util.JDBCUtil;

public class UserDaoImpl implements IUserDao {

	
	public List<User> findByUser(String name, String password) {
	//public User findByUser(String name, String password) {
		Connection connection = null;
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		List<User> list = new ArrayList<>();
		try {
			connection = JDBCUtil.getConnection();
			String sql = "select name,password from user";
			preparedStatement = connection.prepareStatement(sql);
			resultSet = preparedStatement.executeQuery();
			while (resultSet.next()) {
				name = resultSet.getString("name");
				password = resultSet.getString("password");
				User user = new User(name,password);
				list.add(user);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			JDBCUtil.close(connection, null, resultSet, preparedStatement);
		}
		
		return list;
	}

}
